package chapter4

import (
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
)

func Midware(ctx *gin.Context) {
	time_start := time.Now()
	fmt.Printf("hello world\n")
	ctx.Next()
	fmt.Print("midware1 over\n")
	time_couter := time.Since(time_start)

	fmt.Printf("time count%v\n", time_couter)
}

func Midware2() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		fmt.Print("ehllo world\n")
		ctx.Next()
		fmt.Print("midware2 over\n")
	}
}

func Midware3(ctx *gin.Context) {
	fmt.Printf("hello world 3\n")
	ctx.Next()
	fmt.Print("midware1 over3\n")
}

var mapvar map[string]interface{} = map[string]interface{}{
	"xiaoming": gin.H{"age": 11, "addr": "fujian"},
	"xiaosi":   gin.H{"age": 15, "addr": "hubei"},
	"xiaowu":   gin.H{"age": 19, "addr": "anhui"},
}

func AuGet(ctx *gin.Context) {
	val := ctx.Query("user_name")
	data := mapvar[val]
	ctx.JSON(200, gin.H{
		"name": val,
		"data": data,
	})
}
